package ClassDay3.Service;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
@Component
//Spring整合的mybaits非常麻烦，需要一步一步慢慢讲,首先先配置mybaits数据库
public class Servlet2 {
    @Bean
    public SqlSessionFactoryBean GetMybaitsFactory(DataSource ds){
        //mybaits创建一个bean工厂，用于创建sql
        SqlSessionFactoryBean Sb=new SqlSessionFactoryBean();
        //b.setTypeAliasesPackage("ClassDay3.Service");//mybaits给指定包下的所有类设置别名
        Sb.setDataSource(ds);//设置
        return Sb;
    }
    @Bean//注解很重要不然添加不到bean里面
    public MapperScannerConfigurer Ms() {
        MapperScannerConfigurer Ms = new MapperScannerConfigurer();//添加映射文件对应的接口
        Ms.setBasePackage("ClassDay3.Ie");
        return Ms;
    }
}
